package com.sky.mapper;

import com.sky.anno.AutoFill;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * add employee
     * @param employee
     */
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into employee ( name, username, password, phone, sex, id_number,  create_time, update_time, "
            + "create_user, update_user,status)  values " +
            "(#{name}," +
            "#{username}," +
            "#{password}," +
            "#{phone}," +
            "#{sex}," +
            " #{idNumber}," +
            "#{createTime}," +
            "#{updateTime}," +
            "#{createUser}," +
            "#{updateUser}," +
            "#{status})")
    void add(Employee employee);


    /**
     * select all employees ordinarily
     * @param employeePageQueryDTO
     * @return
     */
    List<Employee> list(EmployeePageQueryDTO employeePageQueryDTO);

    /**
     * select employee by id
     * @param id
     * @return
     */
    @Select("select id, name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, " +
            "update_user from employee where id=#{id}")
    Employee getById(Integer id);

    /*
    *@Update("update employee set status=#{status},update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    void amendStatus(Employee employee);*/

    @AutoFill(value = OperationType.UPDATE)
    void alterEmp(Employee employee);

    /*
    *@Update("update employee set password=#{password},update_user=#{updateUser}," +
            "update_time=#{updateTime} where id=#{id}")
    void editPassword(Employee employee);*/
    /*以上三个方法可以归结一起，都是更新操作，用动态sql来解决
    * 只需要一个统一的更新语句*/
}
